//
//  CZNetworkTool.swift
//  weibo10
//
//  Created by apple on 16/5/13.
//  Copyright © 2016年 apple. All rights reserved.
//

import UIKit

import AFNetworking


// 请求方法枚举
enum RequestMethod: String {
    case GET = "GET"
    case POST = "POST"
}


 class CZNetworkTool: NSObject
{
//单例
    
    static let sharedInstance: CZNetworkTool = CZNetworkTool()
    
    
    //属性
    private let afnManager:AFHTTPSessionManager = {
    let afn = AFHTTPSessionManager(baseURL: NSURL(string: "https://api.weibo.com/"))
    
    //给响应的序列化器多添加支持的类型
        
      afn.responseSerializer.acceptableContentTypes?.insert("text/plain")
        
   return afn
    }()
    
    
    func request(method: RequestMethod, URLString: String, parameters: AnyObject?, success: ((NSURLSessionDataTask, AnyObject?) -> Void)?, failure: ((NSURLSessionDataTask?, NSError) -> Void)?) {
        if method == RequestMethod.GET {
            afnManager.GET(URLString, parameters: parameters, progress: nil, success: success, failure: failure)
        } else {
            afnManager.POST(URLString, parameters: parameters, progress: nil, success: success, failure: failure)
        }
    }

    
    

}